package com.ymatou.iapi.productmanager.testcase.old202012;

import java.util.Arrays;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.productmanager.parameter.QueryAlhSelectionProductsBean;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmanager.service.QueryAlhSelectionProductsCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.business.service.ProductManagerCallServiceV3;
import com.ymttest.utils.EnvSetup;

/**
 * 查询可加入的商品列表 FreeMaker Template自动生成代码
 */
@TestSuite
@Ignore
public class Ts_QueryAlhSelectionProducts {
	private static QueryAlhSelectionProductsBean QueryAlhSelectionProductsBean;
	private static QueryAlhSelectionProductsCall QueryAlhSelectionProductsCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("productsellerid"));
	private static String sellerName = EnvSetup.getData("productsellername");

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询可加入的商品列表(202005废弃)");
	}

	@Before
	public void caseUp() {
		QueryAlhSelectionProductsBean = new QueryAlhSelectionProductsBean();
		QueryAlhSelectionProductsCall = new QueryAlhSelectionProductsCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(QueryAlhSelectionProductsCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}


	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_QueryAlhSelectionProducts_001() {
		Logger.start(true, "根据买手id进行查询,查询成功");
		try {

			QueryAlhSelectionProductsBean.setUserId(sellerId);
			QueryAlhSelectionProductsBean.setPageIndex(1);
			QueryAlhSelectionProductsBean.setPageSize(100);
			
			
			QueryAlhSelectionProductsCall.setData(QueryAlhSelectionProductsBean);
			QueryAlhSelectionProductsCall.callService();
			Logger.verifyEquals("200", QueryAlhSelectionProductsCall.getJsonObject().get("Code").getAsString(), "验证Code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_QueryAlhSelectionProducts_002() {
		Logger.start(true, "根据买手id与商品名称进行查询,查询成功");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV3.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject()
					.get("ProductId").getAsString();
			Thread.sleep(5000);
			QueryAlhSelectionProductsBean.setUserId(sellerId);
			QueryAlhSelectionProductsBean.setTitle(addProdReq.getProduct().getProductName());
			QueryAlhSelectionProductsBean.setPageIndex(1);
			QueryAlhSelectionProductsBean.setPageSize(100);
			 
			QueryAlhSelectionProductsCall.setData(QueryAlhSelectionProductsBean);
			QueryAlhSelectionProductsCall.callService();
			Logger.verifyEquals("200", QueryAlhSelectionProductsCall.getJsonObject().get("Code").getAsString(), "验证Code");
			Logger.verifyNotEquals(-1, QueryAlhSelectionProductsCall.getJsonObject().toString().indexOf(productId), "查询结果是否包含此商品");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_QueryAlhSelectionProducts_003() {
		Logger.start(true, "根据买手id、二级类目id进行查询,查询成功");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV3.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject()
					.get("ProductId").getAsString();
			Thread.sleep(5000);
			QueryAlhSelectionProductsBean.setUserId(sellerId);
			QueryAlhSelectionProductsBean.setSecondCategoryId(addProdReq.getProduct().getSecondCategoryId());
			QueryAlhSelectionProductsBean.setPageIndex(1);
			QueryAlhSelectionProductsBean.setPageSize(100);
			
			QueryAlhSelectionProductsCall.setData(QueryAlhSelectionProductsBean);
			QueryAlhSelectionProductsCall.callService();
			Logger.verifyEquals("200", QueryAlhSelectionProductsCall.getJsonObject().get("Code").getAsString(), "验证Code");
			Logger.verifyNotEquals(-1, QueryAlhSelectionProductsCall.getJsonObject().toString().indexOf(productId), "查询结果是否包含此商品");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_QueryAlhSelectionProducts_004() {
		Logger.start(true, "根据买手id、品牌进行查询,查询成功");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV3.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject()
					.get("ProductId").getAsString();
			Thread.sleep(5000);
			QueryAlhSelectionProductsBean.setUserId(sellerId);
			QueryAlhSelectionProductsBean.setBrandName("Nike");;
			QueryAlhSelectionProductsBean.setPageIndex(1);
			QueryAlhSelectionProductsBean.setPageSize(100);
			
			QueryAlhSelectionProductsCall.setData(QueryAlhSelectionProductsBean);
			QueryAlhSelectionProductsCall.callService();
			Logger.verifyEquals("200", QueryAlhSelectionProductsCall.getJsonObject().get("Code").getAsString(), "验证Code");
			Logger.verifyNotEquals(-1, QueryAlhSelectionProductsCall.getJsonObject().toString().indexOf(productId), "查询结果是否包含此商品");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_QueryAlhSelectionProducts_005() {
		Logger.start(true, "根据买手id、物流进行查询,查询成功");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV3.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject()
					.get("ProductId").getAsString();
			Thread.sleep(5000);
			QueryAlhSelectionProductsBean.setUserId(sellerId);
			QueryAlhSelectionProductsBean.setDeliveryMethod(Arrays.asList(addProdReq.getProduct().getPackageDeliveryType()));
			QueryAlhSelectionProductsBean.setPageIndex(1);
			QueryAlhSelectionProductsBean.setPageSize(100);
			
			QueryAlhSelectionProductsCall.setData(QueryAlhSelectionProductsBean);
			QueryAlhSelectionProductsCall.callService();
			Logger.verifyEquals("200", QueryAlhSelectionProductsCall.getJsonObject().get("Code").getAsString(), "验证Code");
			Logger.verifyNotEquals(-1, QueryAlhSelectionProductsCall.getJsonObject().toString().indexOf(productId), "查询结果是否包含此商品");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_QueryAlhSelectionProducts_006() {
		Logger.start(true, "根据买手id、不在安利会推广中的商品进行查询,查询成功");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV3.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject()
					.get("ProductId").getAsString();
			Thread.sleep(5000);
			QueryAlhSelectionProductsBean.setUserId(sellerId);
			QueryAlhSelectionProductsBean.setAlhType(1);
			QueryAlhSelectionProductsBean.setPageIndex(1);
			QueryAlhSelectionProductsBean.setPageSize(100);
			
			QueryAlhSelectionProductsCall.setData(QueryAlhSelectionProductsBean);
			QueryAlhSelectionProductsCall.callService();
			Logger.verifyEquals("200", QueryAlhSelectionProductsCall.getJsonObject().get("Code").getAsString(), "验证Code");
			Logger.verifyEquals("null", QueryAlhSelectionProductsCall.getJsonObject().get("Data").toString(), "没有查询到数据");
//			Logger.verifyNotEquals(-1, QueryAlhSelectionProductsCall.getJsonObject().toString().indexOf(productId), "查询结果是否包含此商品");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_QueryAlhSelectionProducts_007() {
		Logger.start(true, "当买手id不存在的时候，查询失败");
		try {
			QueryAlhSelectionProductsBean.setUserId(1312312388);
			QueryAlhSelectionProductsBean.setPageIndex(1);
			QueryAlhSelectionProductsBean.setPageSize(100);
			
			QueryAlhSelectionProductsCall.setData(QueryAlhSelectionProductsBean);
			QueryAlhSelectionProductsCall.callService();
			Logger.verifyEquals("200", QueryAlhSelectionProductsCall.getJsonObject().get("Code").getAsString(), "验证Code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

}